import request from "@/utils/request";

const GENERATOR_BASE_URL = "/client";
const ShipFavoritesAPI = {
  /**
   * 收藏船舶
   * @param data 收藏参数
   */
  addFavorite(data: { shipId: number }) {
    return request<APIResponse<{ favoriteId: number }>>({
      url: `${GENERATOR_BASE_URL}/ship/favorites`,
      method: "post",
      data
    });
  },

  /**
   * 获取收藏列表
   * @param params 查询参数
   */
  getFavoritesList(params: {
    pageNum: string;
    pageSize: string;
    uid: string;
  }) {
    return request<APIResponse<FavoriteItem[]>>({
      url: `/ship/favorites/list`,
      method: "get",
      params: {
        ...params,
        // 类型转换示例（根据实际需要）
        pageNum: parseInt(params.pageNum, 10),
        pageSize: parseInt(params.pageSize, 10)
      }
    });
  },

  /**
   * 取消收藏
   * @param favoriteId 收藏记录ID
   */
  removeFavorite(favoriteId: number) {
    return request<APIResponse<null>>({
      url: `${GENERATOR_BASE_URL}/ship/favorites`,
      method: "delete",
      data: { favoriteId } // 或使用 params: { shipId }
    });
  }
};

// types.ts
interface FavoriteItem {
  favoriteId: number;
  userId: number;
  shipId: number;
  shipInfo: {
    shipName: string;
    thumbnail: string;
    currentPort: string;
  };
  createTime: string;
}

interface APIResponse<T> {
  code: number;
  msg: string;
  rows: T;
  total?: number;
}
